<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
    <title>采购管理 收货地址管理  用户列表（医疗机构端）</title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp"%>
</head>

<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">

    <section class="content-header">
    </section>
    
    <section class="content">
        <div class=" box box-success">
            <div class="box-body">
                <div class=" form-inline">
                
                    <div class="form-group form-group-xs">
                        <label for="searchrecpAddr">账号：</label>
                        <input class="form-control" type="text" id="username" name="username" placeholder="账号" />
                    </div>
                    
                    <div class="form-group form-group-xs">
                        <label for="searchrecpAddr">用户名：</label>
                        <input class="form-control" type="text" id="name" name="name" placeholder="用户名" />
                    </div>
                    
                    <button  id="selectSee" type="button" class="btn btn-success btn-sm" onclick="search()">查&nbsp;询</button>
                    
                </div>
            </div>
        </div>
        
        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>
        
        <div class=" box box-warning bottongroup">
            <button type="button" id="userSelect"  onclick="userSelect();" class="btn btn-primary btn-sm">选&nbsp;择</button>
        </div>
        
    </section>
    
    <%@ include file="/WEB-INF/component/commonJS.jsp"%>
    <script type="text/javascript">
    
  //绑定回车   id="selectSee"
    $('#username,#name').bind('keydown', function(event) {
        if (event.keyCode == "13") {
            $('#selectSee').click();
        }
    }); 
    $("#username").focus();//加载页面光标在第一个查询框内 

        $(function () {
        	var userIds = "${userIds}";
        	var userIdList = [];
        	if (userIds != null && userIds.length > 0) {
        		userIdList = userIds.split(";");
        	}
        	
        	function checkSelected(id) {
        		if (userIdList.length > 0) {
        			for (var i=0; i<userIdList.length; i++) {
        				if (userIdList[i] == id) {
        					return true;
        				}
        			}
        		}
        		return false;
        	}
        	
            $("#gridlist").jqGrid({
                url: "getUserList.html",
                mtype: "POST",
                datatype: "json",
                autowidth: true,
                height: 270,
                colNames: ['id', '账号', '用户名', '邮件', '用户电话'],
                colModel: [
                    { name: 'id', hidden:true, width: 100 , align:"center" ,sortable: false},
                    { name: 'username', width: 80 , align:"center" ,sortable: false},
                    { name: 'name', width: 120 , align:"center" ,sortable: false},
                    { name: 'email', width: 100 , align:"center" ,sortable: false},
                    { name: 'phone', width: 80 , align:"center",sortable: false }
                ],
                rowNum: 20,
                rowList: [10, 20,50,100],
                rownumbers: true,
                multiselect: true,
                pager: "#gridpage",
                viewrecords: true,
                caption: "用户列表 ",
                jsonReader: {
                    repeatitems: false,
                    id: "id"
                },
                gridComplete: function() {
                	var ids = $("#gridlist").jqGrid('getDataIDs');
                	if (ids.length > 0) {
                		for (var i=0; i<ids.length; i++) {
                			var id = ids[i];
                			if (checkSelected(id)) {
                				$("#gridlist").setSelection(id);
                			}
                		}
                	}
                }
            });
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            $(window).trigger("resize");
        });
        
        /* 查询 */
        function search(page) {
            var username = $.trim($("#username").val());
            var name = $.trim($("#name").val());
            $("#gridlist").jqGrid("clearGridData");
                $("#gridlist").jqGrid('setGridParam',{  
                mtype: "POST",
                datatype:'json',
                postData:{"username":username,"name":name},
                page : (page || 1)
            }).trigger("reloadGrid"); //重新载入  
        }
        
        /* 选择 */
        function userSelect(){
        	var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
        	if (rowIds.length <= 0) {
                $.HN.message.alert('请选择用户！', '提示信息', 'warn');
                return ;
            }
        	 var userList = [];
             for (var i=0; i<rowIds.length; i++) {
                 var rowId = rowIds[i];
                 var rowdata = $("#gridlist").jqGrid('getRowData', rowId);
                 userList.push({"id":rowId, "name":(rowdata.name || "")});
             }
             var dialog = top.dialog.get(window);
             dialog.close(userList); // 关闭（隐藏）对话框
             dialog.remove();                // 主动销毁对话框
            return false;
        }
        
        
    </script>
</body>
</html>